﻿package com.shawnblais.sitecontrol
{
    import com.gskinner.motion.*;
    import com.shawnblais.pages.*;
    
    import fl.motion.easing.*;
    
    import flash.display.*;
    import flash.events.*;
      import mcSettings;
    public class SiteView extends MovieClip
    {
        public var content:Object;
        public var settings_mc:*
        protected var _data:SiteData;
        protected var _controller:SiteControl;

        public function SiteView(param1, param2)
        {
            this._data = param1;
            this._controller = param2;
            this.addEventListener(Event.ADDED_TO_STAGE, this.init);
            return;
        }// end function

        protected function toggleDOF(event:Event)
        {
            this.content.useDepthOfField = event.target.checked;
            this.content.setDepthOfField();
            return;
        }// end function

        private function unloadPage() : void
        {
            return;
        }// end function

        protected function toggleFullscreen(event:Event = null)
        {
            this.content.useFullscreen = !this.content.useFullscreen;
            this.onStageResize();
            return;
        }// end function

        private function init(event:Event)
        {
            this.settings_mc = new mcSettings() ;
            addChild(this.settings_mc);
            this.settings_mc.x = 15;
            this.settings_mc.addEventListener("ToggleDOF", this.toggleDOF);
            this.settings_mc.addEventListener("ToggleFullscreen", this.toggleFullscreen);
            return;
        }// end function

        public function loadPage(addChild:int = 0) : void
        {
            this.content = new Page3D();
            addChildAt(this.content as DisplayObject,0);
            this.content.init();
            return; 
        }// end function

        public function onStageResize()
        {
            if (this.content.useFullscreen)
            {
                this.content.viewport.viewportWidth = stage.stageWidth;
                this.content.viewport.viewportHeight = stage.stageHeight;
                var _loc_1:int = 0;
                this.content.y = 0;
                this.content.x = _loc_1;
                this.content.pageBorder_mc.visible = false;
            }
            else
            {
                this.content.viewport.viewportWidth = this.content.minWidth;
                this.content.viewport.viewportHeight = this.content.minHeight;
                this.content.x = stage.stageWidth / 2 - this.content.minWidth / 2;
                this.content.y = stage.stageHeight / 2 - this.content.minHeight / 2;
                this.content.pageBorder_mc.visible = true;
            }
            this.content.startButton_mc.x = this.content.viewport.viewportWidth / 2;
            this.content.startButton_mc.y = this.content.viewport.viewportHeight / 2 - 700;
            new GTween(this.content.startButton_mc, 1.1, {x:this.content.viewport.viewportWidth / 2, y:this.content.viewport.viewportHeight / 2}, {ease:Bounce.easeOut});
            this.settings_mc.y = stage.stageHeight - 15;
            return;
        }// end function

    }
}
